home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CDialogs.h
-
- Contains: Layer built on top of the Dialog Manager
-
- Written by: Arno Gourdol
-
- Copyright: © 1994-1995 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #pragma once
-
- #ifndef __CDIALOGS__
- #define __CDIALOGS__
-
- #include <Dialogs.h>
- #include <ToolUtils.h>
-
- #include "CWindows.h"
- #include "CFonts.h"
-
- #define kDialogParametersCount 16 // max number of parameter text in a dialog
- #define kStyledTextCount 32 // max number of items with styled text
-
- struct DialogParameter
- {
- Str15 key; // The string that will be replaced,
- // for example "<name>"
- Str255 value; // The value by which the key will
- // be replaced
- SInt16 dialogItem; // If the dialog item only contains the
- // key, index of the dialog item
- };
-
-
- class CDialog : public CWindow
- {
- public:
- // constructor
- CDialog(SInt16 dialogID, FontCode fontCode = kSystemFont);
-
- // destructor
- virtual ~CDialog(void);
-
- // modifiers
- virtual WindowRef MakeWindow(void);
- virtual DialogRef MakeDialog(void);
- virtual void Close(void);
-
- virtual void Draw(TDrawContext& drawContext);
-
- // modifiers
- virtual void ItemHit(short itemHit);
- void DoPrepareDialog(void);
- virtual void PrepareDialog(void);
- virtual void SubstituteParameters(void);
- virtual void DrawUserItem(TDrawContext& drawContext, short item, const CRect& frame);
- void SetParameter(ConstStr15Param key, ConstStr255Param value);
- void GetParameter(ConstStr15Param key, Str255 value);
- inline void SetDefaultButton(short itemNumber);
- inline void SetCancelButton(short itemNumber);
- inline void SetDefaultButtonName(ConstStr63Param buttonName);
- virtual Boolean FilterEvent(const EventRecord &event);
- inline void SetNextDialog(CDialog *theDialog);
- void AddKeyboardShortcuts(short stringID);
- // all strings in the STR# take the form "X:N", where X is the key and N the item number
-
- // Keyboard navigation
- short FirstTextField(void);
- short LastTextField(void);
- short PreviousTextField(short item = 0);
- short NextTextField(short item = 0);
-
- // selectors
- inline DialogRef GetDialogRef(void);
- GDHandle GetMaxIntersectedDevice(class CRect& screenRect);
- static CDialog* GetCDialog(DialogRef dialog);
- inline CDialog* GetNextDialog(void);
- virtual Boolean CheckKeyboardShortcuts(const EventRecord &event);
- TEHandle GetStyledText(short item);
- void SetStyledText(short item, TEHandle styledText);
-
- // dialog utilities
- inline void SetDrawingProc(short item, UserItemUPP proc);
- inline CRect GetItemRect(short item);
- void SetItemRect(short item, const CRect &newRect);
- inline ControlRef GetItemControl(short item);
- void SetItemControl(short item, ControlRef control);
- inline Handle GetItemData(short item);
- inline void SetItemData(short item, Handle data);
- inline void GetItemText(short item, Str255 s);
- void SetItemText(short item, ConstStr255Param s);
- inline void SelectItemText(short item, short start = 0, short finish = 32767);
- inline void SetItemValue(short item, short value);
- inline short GetItemValue(short item);
- inline short GetItemHilite(short item);
- inline void HiliteItem(short item, short hilite);
- inline void EnableItem(short item, Boolean enable = true);
- inline void DisableItem(short item);
- inline Boolean IsEnabled(short item);
- inline void GetItemTitle(short item, Str255 title);
- inline void SetItemTitle(short item, ConstStr255Param title);
- inline short GetItemType(short item);
- inline void SetItemType(short item, short theType);
- inline void HideItem(short item);
- inline void ShowItem(short item);
- inline void FlashButton(short item);
- inline void GetSelectionEndpoints(short &start, short &end);
- inline short GetItemTextSize(short item = 0);
- void PasteText(Ptr text, short size);
-
- CFontSpec fDialogFont;
-
- protected:
- SInt16 fDialogID;
- DialogRef fDialog;
-
- short fDefaultButton; // item number of the default button
- short fCancelButton; // item number of the cancel button
-
- UserItemUPP fUserItemCallback;
-
- // Data for parameter substitution
- DialogParameter fParameters[kDialogParametersCount];
-
- // Private data stored with each item
- short fStyleTextItem[kStyledTextCount];
- TEHandle fStyledText[kStyledTextCount];
-
- // linked list of dialogs used to turn dialog pointers into CDialogs
- static CDialog *gDialogList;
- CDialog* fNextDialog;
-
- // keyboard shortcuts array
- short fNumShortcuts;
- struct Shortcut { UInt16 key; UInt16 item; } *fShortcuts;
-
- private:
- static pascal void UserItemCallback(DialogRef dialog, short item);
- };
-
- void CDialog::SetNextDialog(CDialog *theDialog)
- {
- fNextDialog = theDialog;
- }
-
- DialogRef CDialog::GetDialogRef(void)
- {
- return fDialog;
- }
-
- CDialog* CDialog::GetNextDialog(void)
- {
- return fNextDialog;
- }
-
- void CDialog::SetDrawingProc(short item, UserItemUPP proc)
- {
- assert(GetItemType(item) == userItem);
- SetItemData(item, (Handle)proc);
- }
-
- CRect CDialog::GetItemRect(short item)
- {
- Handle h;
- short type;
- CRect r;
-
- GetDialogItem(GetDialogRef(), item, &type, &h, r);
-
- return r;
- }
-
- Handle CDialog::GetItemData(short item)
- {
- Rect r;
- Handle h;
- short type;
-
- GetDialogItem(GetDialogRef(), item, &type, &h, &r);
- return h;
- }
-
- void CDialog::SetItemData(short item, Handle data)
- {
- Rect r;
- Handle h;
- short type;
-
- GetDialogItem(GetDialogRef(), item, &type, &h, &r);
- SetDialogItem(GetDialogRef(), item, type, data, &r);
- }
-
- void CDialog::GetItemText(short item, Str255 s)
- {
- assert(GetItemType(item) == statText || GetItemType(item) == editText);
-
- GetDialogItemText(GetItemData(item), s);
- }
-
- void CDialog::SelectItemText(short item, short start, short finish)
- {
- assert(GetItemType(item) == editText);
-
- SelectDialogItemText(GetDialogRef(), item, start, finish);
- }
-
- ControlRef CDialog::GetItemControl(short item)
- {
- Rect r;
- Handle h;
- short type;
-
- GetDialogItem(GetDialogRef(), item, &type, &h, &r);
- assert((type & ctrlItem) == ctrlItem);
- return (ControlRef)h;
- }
-
- void CDialog::SetItemValue(short item, short value)
- {
- ControlRef control = GetItemControl(item);
- if (value != GetControlValue(control))
- SetControlValue(control, value);
- }
-
- short CDialog::GetItemValue(short item)
- {
- return GetControlValue(GetItemControl(item));
- }
-
- short CDialog::GetItemHilite(short item)
- {
- short result = (**GetItemControl(item)).contrlHilite;
- return result;
- }
-
-
- void CDialog::HiliteItem(short item, short hilite)
- {
- if (GetItemHilite(item) != hilite)
- {
- HiliteControl(GetItemControl(item), hilite);
- }
- }
-
- void CDialog::EnableItem(short item, Boolean enable)
- {
- HiliteItem(item, enable ? 0 : 255);
- assert(IsEnabled(item) == enable);
- }
-
- void CDialog::DisableItem(short item)
- {
- HiliteItem(item, 255);
- assert(!IsEnabled(item));
- }
-
- Boolean CDialog::IsEnabled(short item)
- {
- return GetItemHilite(item) != 255;
- }
-
- void CDialog::GetItemTitle(short item, Str255 title)
- {
- GetControlTitle(GetItemControl(item), title);
- }
-
- void CDialog::SetItemTitle(short item, ConstStr255Param title)
- {
- ControlRef control = GetItemControl(item);
- Str255 s;
- GetControlTitle(control, s);
- if (!EqualString(s, title, true, true))
- SetControlTitle(control, title);
- }
-
- short CDialog::GetItemType(short item)
- {
- Rect r;
- Handle h;
- short type;
-
- GetDialogItem(GetDialogRef(), item, &type, &h, &r);
-
- return type & ~itemDisable;
- }
-
- void CDialog::SetItemType(short item, short theType)
- {
- Rect r;
- Handle h;
- short type;
-
- GetDialogItem(GetDialogRef(), item, &type, &h, &r);
- SetDialogItem(GetDialogRef(), item, theType | (type & itemDisable), h, &r);
- }
-
- void CDialog::HideItem(short item)
- {
- HideDialogItem(GetDialogRef(), item);
- }
-
- void CDialog::ShowItem(short item)
- {
- ShowDialogItem(GetDialogRef(), item);
- }
-
- void CDialog::FlashButton(short item)
- {
- if (IsEnabled(item))
- {
- long waitTicks;
- HiliteItem(item, kControlButtonPart);
- Delay(8, &waitTicks);
- HiliteItem(item, 0);
- }
- }
-
- void CDialog::GetSelectionEndpoints(short& start, short& end)
- {
- TEHandle te = ((DialogPeek)GetDialogRef())->textH;
- end = (**te).selEnd;
- start = (**te).selStart;
- }
-
- short CDialog::GetItemTextSize(short item)
- {
- Str255 s;
- if (item == 0)
- {
- GetItemText(((DialogPeek)GetDialogRef())->editField + 1, s);
- }
- else
- {
- GetItemText(item, s);
- }
- return s[0];
- }
-
-
-
-
- #endif
-